<?php

namespace app\model\store;

use app\model\delivery\DeliveryOrder;
use app\model\delivery\DeliveryOrderItem;
use app\model\site\User;
use think\Model;

class Order extends Model
{
    // 订单关联用户
    public function user(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    // 订单关联的商品
    public function items(): \think\model\relation\HasMany
    {
        return $this->hasMany(OrderItem::class, 'order_id');
    }

    // 订单关联的发货单
    public function deliveryOrders(): \think\model\relation\HasMany
    {
        return $this->hasMany(DeliveryOrder::class, 'order_id');
    }

    // 订单关联的已发货的商品
    public function deliveryItems(): \think\model\relation\HasMany
    {
        return $this->hasMany(DeliveryOrderItem::class, 'order_id');
    }

    // 关联的售后订单
    public function refunds(): \think\model\relation\HasMany
    {
        return $this->hasMany(OrderRefund::class, 'order_id');
    }

}
